package org.clever.arkdemo.video;


import com.alibaba.fastjson.JSON;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.vod.v20180717.VodClient;
import com.tencentcloudapi.vod.v20180717.models.ConfirmEventsRequest;
import com.tencentcloudapi.vod.v20180717.models.EventContent;
import com.tencentcloudapi.vod.v20180717.models.PullEventsRequest;
import com.tencentcloudapi.vod.v20180717.models.PullEventsResponse;

public class VideoEventPullDemo {
    public static void main(String[] args) throws TencentCloudSDKException {
        /// 腾讯账户获得的 SecretId
        String secretId = "AKIDqWx97ygAQSFo8D3g7KI1Ww85rOhlbCYg";
        /// 腾讯账户获得的 SecretKey
        String secretKey = "vb2EF3c1BAvTrAG8lCONDnBMJ1Vlna8S";

        Long appId = 1258399249L;
        Credential credential = new Credential(secretId, secretKey);
        /// 创建 VodClient
        VodClient vodClient = new VodClient(credential, "");
        /// 创建事件拉取的请求
        PullEventsRequest pullEventsRequest = new PullEventsRequest();
        /// App Id
        pullEventsRequest.setSubAppId(appId);
        /// 获取事件
        while (true) {
            try {
                PullEventsResponse pullEventsResponse = vodClient.PullEvents(pullEventsRequest);
                System.out.println(JSON.toJSONString(pullEventsResponse, true));

                EventContent[] eventSet = pullEventsResponse.getEventSet();
                /// 得到每一个事件。
                for (EventContent eventContent : eventSet) {
                    /// 处理每一个事件。 转码完成、封面生成、视频审核。


                    /// 确认当前事件处理完成。 如果不确认， 30秒后会得到重复的信息。
                    ConfirmEventsRequest confirmEventsRequest = new ConfirmEventsRequest();
                    confirmEventsRequest.setEventHandles(new String[]{eventContent.getEventHandle()});
                    vodClient.ConfirmEvents(confirmEventsRequest);
                }

            } catch (TencentCloudSDKException e) {
                System.out.println(e.getErrorCode());
            }
        }
    }
}
